unit uFileSystem;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Menus;

type
  TSystemFile = class
  private
    cFile: TextFile;
    exst: Boolean;
    path: String;
  protected
  public
    var tiles: Array of String;
    constructor Create(s: String);
    procedure Assign();
    function Exists(): Boolean;
    procedure Reset();
    procedure Rewrite();
    function Read(): String;
    function ReadLn(): String;
    procedure ReadTls(s: String);
    procedure Write(s: String);
    procedure WriteLn(s: String);
    procedure Close();
  end;

var
  publicTiles: Array of String;

procedure getTilesOf(text: String; s: String);

implementation

constructor TSystemFile.Create(s: String);
begin
  if (not SysUtils.FileExists(s)) then
    begin
      SysUtils.FileClose(SysUtils.FileCreate(s));
      exst := false;
    end
  else
    begin
      exst := true;
    end;
  path := s;
end;

procedure TSystemFile.Assign();
begin
  System.AssignFile(cFile, path);
end;

function TSystemFile.Exists(): Boolean;
begin
  result := exst;
end;

procedure TSystemFile.Reset();
begin
  System.Reset(cFile);
end;

procedure TSystemFile.Rewrite();
begin
  System.Rewrite(cFile);
end;

function TSystemFile.Read(): String;
var
  s: String;
begin
  System.Read(cFile, s);
  result := s;
end;

function TSystemFile.ReadLn(): String;
var
  s: String;
begin
  System.ReadLn(cFile, s);
  result := s;
end;

procedure TSystemFile.ReadTls(s: String);
var
  s2: String;
  text: String;
  i: Integer;
begin
  text := '';
  while not System.eof(cFile) do
    begin
      System.Readln(cFile, s2);
      text := text + s2;
    end;
  s2 := '';
  for i := 1 to length(text) do
    begin
      if (text[i] = s) then
        begin
          SetLength(self.tiles, length(self.tiles)+1);
          self.tiles[high(self.tiles)] := s2;
          s2 := '';
        end
      else
        begin
          s2 := s2 + text[i];
        end;
    end;
  if (s2 <> '') then
    begin
      SetLength(self.tiles, length(self.tiles)+1);
      self.tiles[high(self.tiles)] := s2;
    end;
end;

procedure TSystemFile.Write(s: string);
begin
  System.Write(cFile, s);
end;

procedure TSystemFile.WriteLn(s: string);
begin
  System.WriteLn(cFile, s);
end;

procedure TSystemFile.Close();
begin
  System.CloseFile(cFile);
end;

procedure getTilesOf(text: String; s: String);
var
  s2: String;
  i: Integer;
begin
  SetLength(publicTiles, 0);
  s2 := '';
  for i := 1 to length(text) do
    begin
      if (text[i] = s) then
        begin
          SetLength(publicTiles, length(publicTiles)+1);
          publicTiles[high(publicTiles)] := s2;
          s2 := '';
        end
      else
        begin
          s2 := s2 + text[i];
        end;
    end;
  if (s2 <> '') then
    begin
      SetLength(publicTiles, length(publicTiles)+1);
      publicTiles[high(publicTiles)] := s2;
    end;
end;

end.

